<?php
/**
 * Created by PhpStorm.
 * User: 仙女大人
 * Date: 2019/6/6
 * Time: 17:09
 */

namespace app\admin\model;
use think\Model;
use think\Db;

class AuthGroup extends Model
{
    // 设置数据表（不含前缀）
    protected $name = 'auth_group';

    public function authUser(){
        return $this->belongsToMany('User','auth_group_access','uid','group_id');
    }

    public function getRules( $data, $pid){
        $rules =[];
        $index = 0;
        foreach($data as $key=>$val) {
            if ($val['pid'] == $pid) {
                $rules[$index]['id'] = $val['id'];
                $rules[$index]['title'] = $val['title'];
                $rules[$index]['pid'] = $val['pid'];

                $child = $this->getRules($data, $val["id"]);
                if (!empty($child)) {
                    $rules[$index]['children'] = $child;
                }
                $index++;
            }
        }
        return $rules;
    }
}